package com.infodms.dms.actions.sales.marketmanage.planmanage;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.common.FileUploadManager;
import com.infodms.dms.actions.sales.marketmanage.planissued.ActivitiesCostOpera;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.sales.dealer.DealerInfoDao;
import com.infodms.dms.dao.sales.marketmanage.planmanage.ActivitiesPlanManageDao;
import com.infodms.dms.dao.sales.planmanage.SpacePlanManageDao;
import com.infodms.dms.dao.sales.planmanage.SpacePlanReportDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TtCamCampaignCostPO;
import com.infodms.dms.po.TtCamMediaCostPO;
import com.infodms.dms.po.TtCampaignExecutePO;
import com.infodms.dms.po.TtCampaignGroupRPO;
import com.infodms.dms.po.TtCampaignPO;
import com.infodms.dms.po.TtCampaignPoseChkRPO;
import com.infodms.dms.po.TtCampaignSpaceExecutePO;
import com.infodms.dms.po.TtCampaignTargetPO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;

/**
 * 市场管理：区域活动执行方案提报
 * @author fengalon
 *
 */
public class ActivitiesSpacePlanReport {
	public Logger logger = Logger.getLogger(ActivitiesSpacePlanReport.class);   
	SpacePlanManageDao dao  = SpacePlanManageDao.getInstance();
	private ActionContext act = ActionContext.getContext();
	RequestWrapper request = act.getRequest();
	
	/*--------------------------------------------------   url常量  --------------------------------------------------*/
	
	private final String SPACE_PLAN_REPORT_URL = "/jsp/sales/marketmanage/planmanage/activitiesSpacePlanReprot.jsp" ;  // 活动执行方案提报(区域)
	private final String SPACE_PLAN_ADD_URL = "/jsp/sales/marketmanage/planmanage/activitiesSpacePlanAdd.jsp" ;  // 新增活动执行方案提报(区域)
	private final String SPACE_PLAN_DETAIL_URL = "/jsp/sales/marketmanage/planmanage/activitiesSpacePlanDetail.jsp" ; // 活动执行方案提报(区域)明细
	
	/*--------------------------------------------------   对应action方法   --------------------------------------------------*/
	
	public void activitiesPlanReportInit(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String flag = "0" ;
			
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
			
			TtCampaignPoseChkRPO tcpcrp = new TtCampaignPoseChkRPO();
			tcpcrp.setPoseId(logonUser.getPoseId());			
			List list = dao.select(tcpcrp);
			if(!CommonUtils.isNullList(list)){
				flag = "1" ;
			}
			
			act.setOutData("flag", flag) ;
			act.setOutData("areaList", areaList);
			act.setForword(SPACE_PLAN_REPORT_URL);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"活动方案提报页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void activitiesSpacePlanQuery() {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String orgId = logonUser.getOrgId().toString() ;
			String poseId = logonUser.getPoseId().toString() ;
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId")) ;
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo")).trim() ;
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName")).trim() ;
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject")).trim() ;
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate")).trim() ;
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate")).trim() ;
			
			TtCampaignPoseChkRPO tcpcrp = new TtCampaignPoseChkRPO();
			tcpcrp.setPoseId(Long.parseLong(poseId));			
			List list = dao.select(tcpcrp);
			if(!CommonUtils.isNullList(list)){
				tcpcrp = (TtCampaignPoseChkRPO)dao.select(tcpcrp).get(0);
			}else {
				throw new RuntimeException("您没有提报权限，请联系系统管理员！");
			}
			
			Map<String, String> paraMap = new HashMap<String, String>() ;
			paraMap.put("orgId", orgId) ;
			paraMap.put("poseId", poseId) ;
			paraMap.put("areaId", areaId) ;
			paraMap.put("campaignNo", campaignNo) ;
			paraMap.put("campaignName", campaignName) ;
			paraMap.put("campaignSubject", campaignSubject) ;
			paraMap.put("startDate", startDate) ;
			paraMap.put("endDate", endDate) ;
			
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			PageResult<Map<String, Object>> spaActList = SpacePlanReportDao.querySpaceAct(paraMap, curPage, Constant.PAGE_SIZE) ;
			
			act.setOutData("ps", spaActList) ;
		} catch(RuntimeException e) {
			logger.error(e) ;
			act.setException(e) ;
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"区域活动方案查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 活动执行方案提报新增页面初始化
	 */
	public void activitiesPlanReportAddInit(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
			
			List<Map<String, Object>> list = ActivitiesPlanManageDao.getInstance().selectPinPai(oemCompanyId);	// 获取品牌信息

			List<Map<String, Object>> areaList = SpacePlanReportDao.getBussArea(logonUser.getPoseId()) ;		// 根据职位获取业务范围
			
			//Log ID：<1> 
			//Depiction：<方案编号改为自动生成，需客户提供编码规则> 
			//Writer：PGM 
			//Rewrite Date：<2010-08-24> 
			String campaignNo = SequenceManager.getSequence("CPN");//方案编号
			
			act.setOutData("campaignNo", campaignNo);
			act.setOutData("areaList", areaList);
			act.setOutData("list", list);
			act.setForword(SPACE_PLAN_ADD_URL);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"区域活动方案提报新增页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 区域活动执行方案提报明细页面
	 */
	public void activitiesSpacePlanReportDetail(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		List<Map<String, Object>> areaList = SpacePlanReportDao.getBussArea(logonUser.getPoseId()) ;		// 根据职位获取业务范围
		act.setOutData("areaList", areaList);
		try {
			String campaignId = request.getParamValue("campaignId");
			String orgId = request.getParamValue("orgId");
			
			TtCampaignPO mypo1 = new TtCampaignPO();
			mypo1.setCampaignId(Long.parseLong(campaignId));
			TtCampaignPO mypo2 = new TtCampaignPO();
			mypo2=(TtCampaignPO) dao.select(mypo1).get(0);
			
			String areaId=String.valueOf(mypo2.getAreaId());
			
			StringBuffer group_id = new StringBuffer();
			StringBuffer group_code = new StringBuffer();
			
			List<Map<String,String>> actList = ActivitiesPlanManageDao.getInstance().queryActiveVehicleType__(campaignId);
			
			if (!isNullList(actList)) {
				for (int i = 0; i < actList.size(); i++) {
					group_id.append(String.valueOf(actList.get(i).get("GROUP_ID"))).append(",");
					group_code.append(String.valueOf(actList.get(i).get("GROUP_CODE"))).append(",");
				}
			}
			
			group_id.deleteCharAt(group_id.length()-1);
			group_code.deleteCharAt(group_code.length()-1);
			
			Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
			List<Map<String, Object>> list = ActivitiesPlanManageDao.getInstance().selectPinPai(oemCompanyId);
			
			Map<String, Object> map2 = SpacePlanReportDao.activitiesInfoQuery(campaignId, orgId) ;
			String executeId = map2.get("EXECUTE_ID").toString();
			String modelName = dao.getModelName(campaignId);
			
			Map<String, Object> map3 = ActivitiesPlanManageDao.getInstance().activitiesTargetQuery(executeId);
			
			List<Map<String, Object>> list1 = ActivitiesPlanManageDao.getInstance().getActivitiesCostbyId(executeId, campaignId);
			List<Map<String, Object>> list2 = SpacePlanReportDao.getActivitiesMediaCost(executeId);
			List<Map<String, Object>> list3 = ActivitiesPlanManageDao.getInstance().getCheckInfo(executeId);
			
			String costSC = SpacePlanReportDao.getCost(Long.parseLong(orgId), areaId, Constant.COST_TYPE_02) ; // 区域费用
			
			List<Map<String, Object>> executePlans = SpacePlanManageDao.getInstance().getMyExecutePlanByCmpId(campaignId);
			
			//根据campaignId查询上传附件
			List<Map<String, Object>> attachList = ActivitiesPlanManageDao.getInstance().getAttachInfos(campaignId);
			
			act.setOutData("costSC", costSC) ;
			act.setOutData("areaId", areaId) ;
			act.setOutData("group_id", group_id.toString());
			act.setOutData("group_code", group_code.toString());
			act.setOutData("map2", map2);
			act.setOutData("map3", map3);
			act.setOutData("list", list);
			act.setOutData("executePlans", executePlans) ;
			act.setOutData("campaignId", campaignId) ;
			
			String type = "" ;
			if(!isNullList(list1)){
				type = list1.get(0).get("COST_TYPE").toString() ;
				
				act.setOutData("list1", list1);
			}
			if(!isNullList(list2)){
				type = list2.get(0).get("COST_TYPE").toString() ;
				
				act.setOutData("list2", list2);
			}
			
			act.setOutData("type", type) ;
			act.setOutData("list3", list3);
			act.setOutData("modelName",modelName);
			
			if(null!=attachList&&attachList.size()!=0){
				act.setOutData("attachList", attachList);
			}
			
			act.setForword(SPACE_PLAN_DETAIL_URL);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"活动执行方案提报明细页面");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 活动执行方案提报提交
	 */
	public void spacePlanReportConfirm(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String submit = CommonUtils.checkNull(request.getParamValue("subm")) ;						//保存为1，提报为0
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId")) ;						//业务范围ID
			String costType = CommonUtils.checkNull(request.getParamValue("costType")) ;					// 费用类型
			String costSource = CommonUtils.checkNull(request.getParamValue("costSource")) ;				// 费用来源
			
			String []fjids = request.getParamValues("fjids");												//附件ID
			SimpleDateFormat fmat = new SimpleDateFormat ("yyyy-MM-dd");									//时间格式化
			
			if ("0".equals(submit)) {
				ActivitiesCostOpera aco = new ActivitiesCostOpera() ;						//---
				aco.activeExecOpera(areaId, costType, "3", Constant.CAMPAIGN_TYPE_03.toString()) ;		// 3表示大区提报
			}
				
			String campaignId = insertCampaign(areaId, fmat) ;
			
			insertCampaignGroupR(campaignId) ;
			
			String executeId = insertSpaceExecute(campaignId, submit) ;
			insertCampaignTarget(executeId) ;
			String camCostId = insertCampaignCost(costType, campaignId, executeId, fmat, null) ;
			String MedCostId = insertMediaCost(executeId, fmat, costType,  null) ;
			
			//附件添加
			FileUploadManager.fileUploadByBusiness(campaignId, fjids, logonUser);
			
			ExecuteOpera(campaignId, submit, fmat, camCostId, MedCostId, costType, costSource) ;
			
			act.setOutData("returnValue", 1);
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.PUTIN_FAILURE_CODE,"区域活动方案提报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void spacePlanReportModify() {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String submit = CommonUtils.checkNull(request.getParamValue("subm")) ;						//保存为1，提报为0
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId")) ;						//业务范围ID
			String costType = CommonUtils.checkNull(request.getParamValue("costType")) ;					// 费用类型
			String costSource = CommonUtils.checkNull(request.getParamValue("costSource")) ;				// 费用来源
			
			String []fjids = request.getParamValues("fjids");												//附件ID
			SimpleDateFormat fmat = new SimpleDateFormat ("yyyy-MM-dd");									//时间格式化
			
			if ("0".equals(submit)) {
				ActivitiesCostOpera aco = new ActivitiesCostOpera() ;						//---
				aco.activeExecOpera(areaId, costType, "3", Constant.CAMPAIGN_TYPE_03.toString()) ;			// 3表示大区提报
			}
				
			String campaignId = updateCampaign(fmat) ;
			
			updateCampaignGroupR(campaignId) ;
			
			String executeId = updateSpaceExecute(campaignId, submit) ;
			updateCampaignTarget(executeId) ;
			String camCostId = updateCampaignCost(campaignId, executeId, fmat, costType, costSource) ;
			String medCostId = updateMediaCost(executeId, fmat, costType, costSource, null) ;
			
			// 批量删除上传文件
			FileUploadManager.delAllFilesUploadByBusiness(campaignId, null) ;
			//附件添加
			FileUploadManager.fileUploadByBusiness(campaignId, fjids, logonUser);
			
			ExecuteOpera(campaignId, submit, fmat, camCostId, medCostId, costType, costSource) ;
				
			act.setOutData("returnValue", 1);
		}catch(RuntimeException e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.PUTIN_FAILURE_CODE,e.getMessage());
			logger.error(logonUser,e1);
			act.setException(e);
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"区域活动方案提报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 活动执行方案取消
	 */
	public void activitiesPlanCencle(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String campaignId = request.getParamValue("campaignId");					//执行ID
			
			//TT_CAMPAIGN_EXECUTE
			TtCampaignExecutePO ttcep1 = new TtCampaignExecutePO();					//活动方案执行表
			TtCampaignExecutePO ttcep2 = new TtCampaignExecutePO();					//活动方案执行表
			ttcep1.setCampaignId(Long.parseLong(campaignId)) ;
			ttcep2.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_11);
			ttcep2.setUpdateDate(new Date(System.currentTimeMillis()));
			ttcep2.setUpdateBy(logonUser.getUserId());
			
			dao.update(ttcep1,ttcep2);				// 更新经销商方案执行表
			
			TtCampaignSpaceExecutePO tcse1 = new TtCampaignSpaceExecutePO() ;
			TtCampaignSpaceExecutePO tcse2 = new TtCampaignSpaceExecutePO() ;
			tcse1.setCampaignId(Long.parseLong(campaignId)) ;
			tcse2.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_11) ;
			tcse2.setUpdateDate(new Date(System.currentTimeMillis())) ;
			tcse2.setUpdateBy(logonUser.getUserId()) ;
			
			dao.update(tcse1, tcse2) ;				// 更新区域方案执行表
			
			act.setOutData("returnValue", 1);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动执行方案取消");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*--------------------------------------------------   本类中的通用方法   --------------------------------------------------*/
	
	@SuppressWarnings("finally")
	public String insertSpaceExecute(String campaignId, String submit) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		String executeId = SequenceManager.getSequence("");
		try {
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String adviceDesc = CommonUtils.checkNull(request.getParamValue("adviceDesc"));					// 区域建议及整改意见
			String isFleet = "1" ;																			//是否大客户审核,区域默认为否：1
			Long orgId = logonUser.getOrgId() ;
			
			TtCampaignSpaceExecutePO ttcep = new TtCampaignSpaceExecutePO();					//活动方案执行表
			ttcep.setIsFleet(Long.parseLong(isFleet)) ;
			ttcep.setOrgId(orgId) ;
			ttcep.setSpaceId(Long.parseLong(executeId));
			ttcep.setCampaignId(Long.parseLong(campaignId));
			if (!CommonUtils.isNullString(execAddDesc)) {
				ttcep.setExecAddDesc(execAddDesc.trim());
			}
			if (!CommonUtils.isNullString(adviceDesc)) {
				ttcep.setAdviceDesc(adviceDesc.trim());
			}
			
			Long poseId = logonUser.getPoseId() ;
			TtCampaignPoseChkRPO tcpcr  = new TtCampaignPoseChkRPO() ;
			tcpcr.setPoseId(poseId) ;
			List<TtCampaignPoseChkRPO> tcpcrList = dao.select(tcpcr) ;
			Integer checkStatus = null ;
			if (!CommonUtils.isNullList(tcpcrList)) {
				checkStatus = tcpcrList.get(0).getCheckStatus() ;
			}
			
			if("0".equals(submit)) {
				ttcep.setSubmitsDate(new Date(System.currentTimeMillis())) ;
				ttcep.setCheckStatus(checkStatus);
			} else {
				ttcep.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_01);
			}
			
			ttcep.setCreateDate(new Date(System.currentTimeMillis()));
			ttcep.setCreateBy(logonUser.getUserId());
			dao.insert(ttcep);				//插入方案执行表
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"区域方案操作");
			logger.error(logonUser,e1);
			act.setException(e1);
		} finally {
			return executeId ;
		}
	}
	
	@SuppressWarnings("finally")
	public String updateSpaceExecute(String campaignId, String submit) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		String executeId = CommonUtils.checkNull(request.getParamValue("executeId"));
		try {
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String adviceDesc = CommonUtils.checkNull(request.getParamValue("adviceDesc"));					// 区域建议及整改意见
			
			TtCampaignSpaceExecutePO oldTtcep = new TtCampaignSpaceExecutePO();
			oldTtcep.setSpaceId(Long.parseLong(executeId)) ;
			
			TtCampaignSpaceExecutePO ttcep = new TtCampaignSpaceExecutePO();					//活动方案执行表
			if (!CommonUtils.isNullString(execAddDesc)) {
				ttcep.setExecAddDesc(execAddDesc.trim());
			}
			if (!CommonUtils.isNullString(adviceDesc)) {
				ttcep.setAdviceDesc(adviceDesc.trim());
			}
			
			Long poseId = logonUser.getPoseId() ;
			TtCampaignPoseChkRPO tcpcr  = new TtCampaignPoseChkRPO() ;
			tcpcr.setPoseId(poseId) ;
			List<TtCampaignPoseChkRPO> tcpcrList = dao.select(tcpcr) ;
			Integer checkStatus = null ;
			if (!CommonUtils.isNullList(tcpcrList)) {
				checkStatus = tcpcrList.get(0).getCheckStatus() ;
			}
			
			if("0".equals(submit)) {
				ttcep.setSubmitsDate(new Date(System.currentTimeMillis())) ;
				ttcep.setCheckStatus(checkStatus);
			} else {
				ttcep.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_01);
			}
			
			ttcep.setUpdateDate(new Date(System.currentTimeMillis()));
			ttcep.setUpdateBy(logonUser.getUserId());

			dao.update(oldTtcep, ttcep);				//修改方案执行表
			
			TtCampaignExecutePO odlTtcep_D = new TtCampaignExecutePO();					//活动方案执行表
			odlTtcep_D.setCampaignId(Long.parseLong(campaignId)) ;
			dao.delete(odlTtcep_D) ;
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"区域方案操作");
			logger.error(logonUser,e1);
			act.setException(e1);
		} finally {
			return executeId ;
		}
	}
	
	@SuppressWarnings("finally")
	public String insertCampaignExecute(String campaignId, String dealerId, String submit) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		String executeId = SequenceManager.getSequence("");
		try {
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String adviceDesc = CommonUtils.checkNull(request.getParamValue("adviceDesc"));					// 区域建议及整改意见
			String isFleet = "1" ;																			//是否大客户审核,区域默认为否：1
			
			TtCampaignExecutePO ttcep = new TtCampaignExecutePO();					//活动方案执行表
			Long orgId = DealerInfoDao.getInstance().getOrgId(dealerId) ;
			
			ttcep.setIsFleet(Long.parseLong(isFleet)) ;
			ttcep.setOrgId(orgId) ;
			ttcep.setExecuteId(Long.parseLong(executeId));
			ttcep.setCampaignId(Long.parseLong(campaignId));
			ttcep.setDealerId(Long.parseLong(dealerId));
			if (!CommonUtils.isNullString(execAddDesc)) {
				ttcep.setExecAddDesc(execAddDesc.trim());
			}
			if (!CommonUtils.isNullString(adviceDesc)) {
				ttcep.setAdviceDesc(adviceDesc.trim());
			}
			
			Long poseId = logonUser.getPoseId() ;
			TtCampaignPoseChkRPO tcpcr  = new TtCampaignPoseChkRPO() ;
			tcpcr.setPoseId(poseId) ;
			List<TtCampaignPoseChkRPO> tcpcrList = dao.select(tcpcr) ;
			Integer checkStatus = null ;
			if (!CommonUtils.isNullList(tcpcrList)) {
				checkStatus = tcpcrList.get(0).getCheckStatus() ;
			}
			
			if("0".equals(submit)) {
				ttcep.setSubmitsDate(new Date(System.currentTimeMillis())) ;
				ttcep.setCheckStatus(checkStatus);
			} else {
				ttcep.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_01);
			}
			
			ttcep.setCreateDate(new Date(System.currentTimeMillis()));
			ttcep.setCreateBy(logonUser.getUserId());
			dao.insert(ttcep);				//插入方案执行表
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商方案操作");
			logger.error(logonUser,e1);
			act.setException(e1);
		} finally {
			return executeId ;
		}
	}
	
	public void insertCampaignGroupR(String campaignId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String modelId = CommonUtils.checkNull(request.getParamValue("modelId"));						//活动车型ID
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);
			
			TtCampaignGroupRPO tgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
			//插入关系表
			String[] modelIds = modelId.split(",");
			if(modelIds != null && modelIds.length > 0){
				for(int i=0;i < modelIds.length;i++){
					String rid = SequenceManager.getSequence("");
					tgr.setRelationId(new Long(rid));
					tgr.setCampaignId(new Long(campaignId));
					tgr.setCampaignModel(new Long(modelIds[i]));
					tgr.setOemCompanyId(companyId);
					tgr.setCreateDate(new Date(System.currentTimeMillis()));
					tgr.setCreateBy(logonUser.getUserId());
					dao.insert(tgr);
				}
			}			
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"车型关系插入");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void updateCampaignGroupR(String campaignId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String modelId = CommonUtils.checkNull(request.getParamValue("modelId"));						//活动车型ID
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);
			
			TtCampaignGroupRPO oldTgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
			oldTgr.setCampaignId(Long.parseLong(campaignId)) ;
			dao.delete(oldTgr) ;
			
			insertCampaignGroupR(campaignId) ;
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"车型关系修改");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	@SuppressWarnings("finally")
	public String insertCampaign(String areaId,  SimpleDateFormat fmat) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		String campaignId = SequenceManager.getSequence("");
		try {
			// TT_CAMPAIGN
			String groupId = CommonUtils.checkNull(request.getParamValue("groupId"));						//品牌ID
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo"));					//方案编号
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName"));				//方案名称
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));					//开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));						//结束时间
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject"));		//活动主题
			String campaignObject = CommonUtils.checkNull(request.getParamValue("campaignObject"));			//活动对象
			String campaignPurpose = CommonUtils.checkNull(request.getParamValue("campaignPurpose"));		//活动目的
			String campaignNeed = CommonUtils.checkNull(request.getParamValue("campaignNeed"));				//活动要求
			String campaignDesc = CommonUtils.checkNull(request.getParamValue("campaignDesc"));				//活动主要内容
			
			// TT_CAMPAIGN
			TtCampaignPO ttcp = new TtCampaignPO();									//市场活动方案表
			ttcp.setAreaId (Long.parseLong(areaId));
			ttcp.setGroupId(Long.parseLong(groupId));
			ttcp.setCampaignId(Long.parseLong(campaignId));
			ttcp.setCampaignNo(campaignNo.trim());
			ttcp.setCampaignName(campaignName.trim());
			ttcp.setStartDate(fmat.parse(startDate));
			ttcp.setEndDate(fmat.parse(endDate));
			if (null != campaignSubject && !"".equals(campaignSubject)) {
				ttcp.setCampaignSubject(campaignSubject.trim());
			}
			if (null != campaignObject && !"".equals(campaignObject)) {
				ttcp.setCampaignObject(campaignObject.trim());
			}
			if (null != campaignPurpose && !"".equals(campaignPurpose)) {
				ttcp.setCampaignPurpose(campaignPurpose.trim());
			}
			if (null != campaignNeed && !"".equals(campaignNeed)) {
				ttcp.setCampaignNeed(campaignNeed.trim());
			}
			if (null != campaignDesc && !"".equals(campaignDesc)) {
				ttcp.setCampaignDesc(campaignDesc.trim());
			}
			
			ttcp.setCampaignType(Constant.CAMPAIGN_TYPE_03);
			ttcp.setCreateDate(new Date(System.currentTimeMillis()));
			ttcp.setCreateBy(logonUser.getUserId());
			dao.insert(ttcp);				//插入活动方案表	
		} catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"市场活动插入");
			logger.error(logonUser,e1);
			act.setException(e1);
		} finally {
			return campaignId ;
		}
	}
	
	@SuppressWarnings("finally")
	public String updateCampaign(SimpleDateFormat fmat) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		String campaignId = CommonUtils.checkNull(request.getParamValue("campaignId"));
		try {
			// TT_CAMPAIGN
			String groupId = CommonUtils.checkNull(request.getParamValue("groupId"));						//品牌ID
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo"));					//方案编号
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName"));				//方案名称
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));					//开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));						//结束时间
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject"));		//活动主题
			String campaignObject = CommonUtils.checkNull(request.getParamValue("campaignObject"));			//活动对象
			String campaignPurpose = CommonUtils.checkNull(request.getParamValue("campaignPurpose"));		//活动目的
			String campaignNeed = CommonUtils.checkNull(request.getParamValue("campaignNeed"));				//活动要求
			String campaignDesc = CommonUtils.checkNull(request.getParamValue("campaignDesc"));				//活动主要内容
			
			// TT_CAMPAIGN
			TtCampaignPO oldTtcp = new TtCampaignPO() ;
			oldTtcp.setCampaignId(Long.parseLong(campaignId));
			
			TtCampaignPO ttcp = new TtCampaignPO();									//市场活动方案表
			ttcp.setGroupId(Long.parseLong(groupId));
			ttcp.setCampaignNo(campaignNo.trim());
			ttcp.setCampaignName(campaignName.trim());
			ttcp.setStartDate(fmat.parse(startDate));
			ttcp.setEndDate(fmat.parse(endDate));
			if (null != campaignSubject && !"".equals(campaignSubject)) {
				ttcp.setCampaignSubject(campaignSubject.trim());
			}
			if (null != campaignObject && !"".equals(campaignObject)) {
				ttcp.setCampaignObject(campaignObject.trim());
			}
			if (null != campaignPurpose && !"".equals(campaignPurpose)) {
				ttcp.setCampaignPurpose(campaignPurpose.trim());
			}
			if (null != campaignNeed && !"".equals(campaignNeed)) {
				ttcp.setCampaignNeed(campaignNeed.trim());
			}
			if (null != campaignDesc && !"".equals(campaignDesc)) {
				ttcp.setCampaignDesc(campaignDesc.trim());
			}
			
			ttcp.setUpdateDate(new Date(System.currentTimeMillis()));
			ttcp.setUpdateBy(logonUser.getUserId());
			dao.update(oldTtcp, ttcp);				//修改活动方案表	
		} catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"市场活动修改");
			logger.error(logonUser,e1);
			act.setException(e1);
		} finally {
			return campaignId ;
		}
	}
	
	public void insertCampaignTarget(String executeId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			//TT_CAMPAIGN_TARGET
			String callsHousesCntTgt = CommonUtils.checkNull(request.getParamValue("callsHousesCntTgt"));	//来电来店数
			String reserveCntTgt = CommonUtils.checkNull(request.getParamValue("reserveCntTgt"));			//信息留存数
			String orderCntTgt = CommonUtils.checkNull(request.getParamValue("orderCntTgt"));				//订单数
			String deliveryCntTgt = CommonUtils.checkNull(request.getParamValue("deliveryCntTgt"));			//交车数
			
			//TT_CAMPAIGN_TARGET
			TtCampaignTargetPO ttctp = new TtCampaignTargetPO();					//市场活动目标表
			String targetId = SequenceManager.getSequence("");
			ttctp.setTargetId(Long.parseLong(targetId));
			ttctp.setExecuteId(Long.parseLong(executeId));
			if (!CommonUtils.isNullString(callsHousesCntTgt)) {
				ttctp.setCallsHousesCntTgt(Integer.parseInt(callsHousesCntTgt.trim()));
			}
			if (!CommonUtils.isNullString(reserveCntTgt)) {
				ttctp.setReserveCntTgt(Integer.parseInt(reserveCntTgt.trim()));
			}
			if (!CommonUtils.isNullString(orderCntTgt)) {
				ttctp.setOrderCntTgt(Integer.parseInt(orderCntTgt.trim()));
			}
			if (!CommonUtils.isNullString(deliveryCntTgt)) {
				ttctp.setDeliveryCntTgt(Integer.parseInt(deliveryCntTgt.trim()));
			}
			
			ttctp.setCreateDate(new Date(System.currentTimeMillis()));
			ttctp.setCreateBy(logonUser.getUserId());
			dao.insert(ttctp);				//插入活动目标表
		} catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动目标插入");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void updateCampaignTarget(String executeId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			//TT_CAMPAIGN_TARGET
			String callsHousesCntTgt = CommonUtils.checkNull(request.getParamValue("callsHousesCntTgt"));	//来电来店数
			String reserveCntTgt = CommonUtils.checkNull(request.getParamValue("reserveCntTgt"));			//信息留存数
			String orderCntTgt = CommonUtils.checkNull(request.getParamValue("orderCntTgt"));				//订单数
			String deliveryCntTgt = CommonUtils.checkNull(request.getParamValue("deliveryCntTgt"));			//交车数
			
			//TT_CAMPAIGN_TARGET
			TtCampaignTargetPO oldTtctp = new TtCampaignTargetPO();
			oldTtctp.setExecuteId(Long.parseLong(executeId)) ;
			
			TtCampaignTargetPO ttctp = new TtCampaignTargetPO();					//市场活动目标表
			if (!CommonUtils.isNullString(callsHousesCntTgt)) {
				ttctp.setCallsHousesCntTgt(Integer.parseInt(callsHousesCntTgt.trim()));
			}
			if (!CommonUtils.isNullString(reserveCntTgt)) {
				ttctp.setReserveCntTgt(Integer.parseInt(reserveCntTgt.trim()));
			}
			if (!CommonUtils.isNullString(orderCntTgt)) {
				ttctp.setOrderCntTgt(Integer.parseInt(orderCntTgt.trim()));
			}
			if (!CommonUtils.isNullString(deliveryCntTgt)) {
				ttctp.setDeliveryCntTgt(Integer.parseInt(deliveryCntTgt.trim()));
			}
			
			ttctp.setUpdateDate(new Date(System.currentTimeMillis()));
			ttctp.setUpdateBy(logonUser.getUserId());
			dao.update(oldTtctp, ttctp);				//修改活动目标表
		} catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动目标修改");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public String insertCampaignCost(String costType, String campaignId, String executeId, SimpleDateFormat fmat, String spaceCostId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		
		StringBuffer costID = new StringBuffer("") ;
		try {
			//TT_CAM_CAMPAIGN_COST
			String[] itemName = request.getParamValues("itemName") ;										//活动明细
			String[] activityType = request.getParamValues("campaignType") ;								//活动类别
			String[] activityContent = request.getParamValues("itemContent") ;								//活动内容
			String[] itemPrice = request.getParamValues("itemPrice") ;										//活动项目单价
			String[] itemCount = request.getParamValues("itemCount") ;										//活动项目数量
			String[] planCost1 = request.getParamValues("planCost1") ;										//活动计划费用
			String[] itemRemarks__ = request.getParamValues("itemRemark");
			String[] camCostID = null ;
			
			// TT_CAM_CAMPAIGN_COST
			TtCamCampaignCostPO ttccp = null ;
			if (null != itemName && itemName.length > 0 ) {
				for(int i= 0; i<itemName.length; i++){
					ttccp = new TtCamCampaignCostPO();					//市场活动费用表
					
					String costId = SequenceManager.getSequence("") ;
					ttccp.setCostId(Long.parseLong(costId)) ;
					ttccp.setCampaignId(Long.parseLong(campaignId)) ;
					ttccp.setExecuteId(Long.parseLong(executeId)) ;
					ttccp.setCostType(Integer.parseInt(costType)) ;
					
					if(!CommonUtils.isNullString(spaceCostId)) {
						camCostID = spaceCostId.split(",") ;
						ttccp.setSpaceCostId(Long.parseLong(camCostID[i])) ;
					}
					
					if (itemName.length > 0 && null != itemName[i] && !"".equals(itemName[i])) {
						ttccp.setItemName(itemName[i].trim());
					}
					if(null != itemRemarks__ && itemRemarks__.length > 0){
						String tes = itemRemarks__[i];
						if (null != tes && !"".equals(tes.trim())) {
							ttccp.setItemRemark(tes.trim());
						}
					}
					if (itemPrice.length > 0 && null != itemPrice[i] && !"".equals(itemPrice[i])) {
						ttccp.setItemPrice(Double.parseDouble(itemPrice[i].trim()));
					}
					if (itemCount.length > 0 && null != itemCount[i] && !"".equals(itemCount[i])) {
						ttccp.setItemCount(Integer.parseInt(itemCount[i].trim()));
					}
					if (planCost1.length > 0 && null != planCost1[i] && !"".equals(planCost1[i])) {
						String cost1 = planCost1[i].trim() ;
						String[] cost = cost1.split(",") ;
						int len = cost.length ;
						
						String cost11 = "" ;
						for(int j=0; j<len; j++) {
							cost11 = cost11 + cost[j] ;
						}
						ttccp.setPlanCost(Double.parseDouble(cost11));
					}
					if ( null != activityType && activityType.length > 0 && null != activityType[i] && !"".equals(activityType[i])) {
						ttccp.setActivityType(Integer.parseInt(activityType[i].trim()));
					}
					if (null != activityContent && activityContent.length > 0 && null != activityContent[i] && !"".equals(activityContent[i])) {
						ttccp.setActivityContent(activityContent[i].trim());
					}
					
					ttccp.setCreateDate(new Date(System.currentTimeMillis()));
					ttccp.setCreateBy(logonUser.getUserId());
					dao.insert(ttccp);			//插入活动费用表
					
					if(costID.length() == 0) {
						costID.append(costId) ;
					} else {
						costID.append(",").append(costId) ;
					}
				}
			}
		} catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动费用插入");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
		
		return costID.toString() ;
	}
	
	public String updateCampaignCost(String campaignId, String executeId, SimpleDateFormat fmat, String costType, String costSource) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		
		String camCostId = "" ;
		try {
			TtCamCampaignCostPO oldTtccp = new TtCamCampaignCostPO() ;
			oldTtccp.setCampaignId(Long.parseLong(campaignId)) ;
			dao.delete(oldTtccp) ;
			
			camCostId = insertCampaignCost(costType, campaignId, executeId, fmat, null) ;
		}  catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动费用修改");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
		
		return camCostId ;
	}
	
	public String insertMediaCost(String executeId, SimpleDateFormat fmat, String costType, String spaceCostId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		
		StringBuffer costID = new StringBuffer("") ;
		try {
			// TT_CAM_MEDIA_COST
			String[] region = request.getParamValues("region") ;											// 省份
			String[] mediaModel = request.getParamValues("mediaModel") ;									// 车型品牌
			String[] advSubject = request.getParamValues("advSubject") ;									// 媒体投放费用广告主题
			String[] mediaType = request.getParamValues("mediaType") ;										// 媒体类型
			String[] mediaName = request.getParamValues("mediaName") ;										// 媒体名称
			String[] advDate = request.getParamValues("advDate") ;											// 媒体投放费用广告开始日期
			String[] endDate = request.getParamValues("myendDate") ;										// 媒体投放费用广告结束日期
			String[] mediaColumn = request.getParamValues("mediaColumn") ;									// 栏目/套装
			String[] publish = request.getParamValues("publish") ;											// 刊发位置/播出时段
			String[] mediaSize = request.getParamValues("mediaSize") ;										// 规格/版式
			String[] mediaCount = request.getParamValues("mediaCount") ;									// 单日频次
			String[] totalCount = request.getParamValues("totalCount") ;									// 总次数
			String[] mediaPrice = request.getParamValues("mediaPrice") ;									// 媒体投放费用结算价格
			String[] planCost2 = request.getParamValues("planCost2") ;										// 金额（元）
			String[] MedCostID = null ;
			
			// TT_CAM_MEDIA_COST
			TtCamMediaCostPO tcmcp = null ;
			if (null != region && region.length > 0) {
				for(int j=0 ; j<region.length; j++){
					tcmcp	= new TtCamMediaCostPO();
					
					String costId = SequenceManager.getSequence("") ;
					
					tcmcp.setCostId(Long.parseLong(costId));
					tcmcp.setExecuteId(Long.parseLong(executeId));
					tcmcp.setCostType(Integer.parseInt(costType)) ;
					
					if(!CommonUtils.isNullString(spaceCostId)) {
						MedCostID = spaceCostId.split(",") ;
						tcmcp.setSpaceCostId(Long.parseLong(MedCostID[j])) ;
					}
					
					if (!CommonUtils.isNullString(region[j])) {
						tcmcp.setRegion(Integer.parseInt(region[j].trim()));
					}
					
					if (!CommonUtils.isNullString(mediaModel[j])) {
						tcmcp.setMediaModel(Integer.parseInt(mediaModel[j].trim()));
					}
					
					if (!CommonUtils.isNullString(advSubject[j])) {
						tcmcp.setAdvSubject(advSubject[j].trim());
					}
					
					if (!CommonUtils.isNullString(mediaType[j])) {
						tcmcp.setMediaType(Integer.parseInt(mediaType[j].trim()));
					}
					
					if (!CommonUtils.isNullString(mediaName[j])) {
						tcmcp.setMediaName(mediaName[j].trim());
					}
					
					if (!CommonUtils.isNullString(advDate[j])) {
						tcmcp.setAdvDate(fmat.parse(advDate[j].trim()));
					}
					
					if (!CommonUtils.isNullString(endDate[j])) {
						tcmcp.setEndDate(fmat.parse(endDate[j].trim()));
					}
					
					if (!CommonUtils.isNullString(mediaColumn[j])) {
						tcmcp.setMediaColumn(mediaColumn[j].trim());
					}
					
					if (!CommonUtils.isNullString(publish[j])) {
						tcmcp.setMediaPublish(publish[j].trim());
					}
					
					if (!CommonUtils.isNullString(mediaSize[j])) {
						tcmcp.setMediaSize(mediaSize[j].trim());
					}
					
					if (!CommonUtils.isNullString(mediaCount[j])) {
						tcmcp.setItemCount(Integer.parseInt(mediaCount[j].trim()));
					}
					
					if (!CommonUtils.isNullString(totalCount[j])) {
						tcmcp.setTotalCount(Integer.parseInt(totalCount[j].trim()));
					}
					
					if (!CommonUtils.isNullString(mediaPrice[j])) {
						tcmcp.setItemPrice(Double.parseDouble(mediaPrice[j].trim()));
					}
					
					if (!CommonUtils.isNullString(planCost2[j])) {
						String cost1 = planCost2[j].trim() ;
						String[] cost = cost1.split(",") ;
						int len = cost.length ;
						
						String cost11 = "" ;
						for(int i=0; i<len; i++) {
							cost11 = cost11 + cost[i] ;
						}
						tcmcp.setPlanCost(Double.parseDouble(cost11));
					}
					
					tcmcp.setCreateDate(new Date(System.currentTimeMillis()));
					tcmcp.setCreateBy(logonUser.getUserId());
					dao.insert(tcmcp);			//插入媒体投放费用表
					
					if(costID.length() == 0) {
						costID.append(costId) ;
					} else {
						costID.append(",").append(costId) ;
					}
				}
			}
		} catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"媒体费用插入");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
		
		return costID.toString() ;
	}
	
	public String updateMediaCost(String executeId, SimpleDateFormat fmat, String costType, String costSource, String spaceCostId) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		
		String medCostId = "" ;
		try {
			TtCamMediaCostPO oldTcmcp = new TtCamMediaCostPO() ;
			oldTcmcp.setExecuteId(Long.parseLong(executeId)) ;
			List<TtCamMediaCostPO> medCostList = dao.select(oldTcmcp) ;
			
			if(!isNullList(medCostList)) {
				int len = medCostList.size() ;
				for (int i=0; i<len; i++) {
					Long spaceMedCostId = medCostList.get(i).getCostId() ;
					TtCamMediaCostPO lowTcmcp = new TtCamMediaCostPO() ;
					lowTcmcp.setSpaceCostId(spaceMedCostId) ;
					
					dao.delete(lowTcmcp) ;
				}
			}
			
			dao.delete(oldTcmcp) ;
			
			medCostId = insertMediaCost(executeId, fmat, costType, spaceCostId) ;
		}catch(Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"媒体费用修改");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
		
		return medCostId ;
	}
	
	public void ExecuteOpera(String campaignId, String submit, SimpleDateFormat fmat, String camCostId, String MedCostId, String costType, String costSource) {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			//执行方案下发的经销商Id
			String[] dlrIds = request.getParamValues("dlrIds");
			String executeId = "" ;
			
			if(null != dlrIds && dlrIds.length > 0){
				for(int i=0; i<dlrIds.length; i++){
					// 查询执行方案表中是否存在该经销商的数据
					List<Map<String, Object>> executePlans = dao.getExecutePlanByCmpId(campaignId,dlrIds[i]);
					
					//如果不存在插入
					if(isNullList(executePlans)){
						executeId = insertCampaignExecute(campaignId, dlrIds[i], submit) ;
						insertCampaignTarget(executeId) ;
						insertCampaignCost(costType, campaignId, executeId, fmat, camCostId) ;
						insertMediaCost(executeId, fmat, costType, MedCostId) ;
						// FileUploadManager.fileUploadByBusiness(executeId, fjids, logonUser);
					}
				}
			}
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"区域可用费用查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void changeCost() {
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId")) ;
			Long orgId = logonUser.getOrgId() ;
			
			String costSC = SpacePlanReportDao.getCost(orgId, areaId, Constant.COST_TYPE_02) ;
			
			act.setOutData("costSC", costSC);
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"区域可用费用查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*--------------------------------------------------   本类中的Util方法   --------------------------------------------------*/
	
	public static boolean isNullList(List<?> list) {
		if (null == list || list.size() <= 0) {
			return true ;
		}
		
		return false ;
	}
}
